/*
* 包含多个更新state函数的对象
* */
import {ADD, ALLSELECT, READTODOS, REMOVE, REMOVEALLTODOS} from "./mutations-type";

export default {
  //更新state：添加todo
  [ADD](state, todo){
    state.todos.push(todo);
  },

  //更新state: 删除todo
  [REMOVE](state, index){
    state.todos.splice(index, 1);
  },

  //更新state：全选
  [ALLSELECT](state, isSelect){
    state.todos.forEach(todo => todo.complete = isSelect)
  },

  //更新state：清除所有已经选中的todo
  [REMOVEALLTODOS](state){
    state.todos = state.todos.filter(todo => !todo.complete)
  }


  //更新state: 缓存todos
  // [READTODOS](state, todos){
  //   state.todos = todos
  // }
}
